﻿using RPCServer.Core;
using RPCServer.Struct;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace RPCServer.Network
{
    class MBufferPacket
    {
        int _bufferSize;

        public void SetBufferSize(int size)
        {

        }

        //public MBuffer Pack(MBuffer buffer)
        //{

        //}

        public void UnPack(MBuffer buffer, Action<MBuffer> Complete)
        {
            if (_bufferSize == 0) return;

            while (buffer.TryReadInt32(out int len))
            {
                if(_bufferSize < len)
                {
                    //TODO
                }
                MBuffer packBuffer = GlobalMBufferManager.Instance.GetBuffer(_bufferSize);
                packBuffer.Write(buffer);
                if (packBuffer.FreeSize == 0)
                    Complete?.Invoke(packBuffer);
            }
        }
    }
}
